# Flask示例：app.py
import time

from flask import Flask, request, jsonify

import config
import db3
import schedule

app = Flask(__name__)


@app.route('/generate', methods=['post'])
def generate_schedule():
    data = request.get_json()
    deptId = data['deptId']
    year = data['year']
    term = data['term']
    ArrUser = data['ArrUser']
    s_Time = time.time()
    try:
        schedule.schedule(deptId, year, term, ArrUser)
        # 状态返回
        return "ok"
    except Exception as e:
        print(e)
        db3.UpdateSchedulingStatus_end(0, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(s_Time)), "异常结束", ArrUser,
                                       time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()), config.MaxIter)
        return "no"


# 程序入口
if __name__ == '__main__':
    app.run(port=9090)
